package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Description NursingLevelController
 * @Author zhangsuye
 * @Date 2024-10-18
 */
@RestController
@Api(tags = "护理等级相关接口")
@RequestMapping("/nursingLevel")
public class NursingLevelController extends BaseController{

    @Autowired
    private NursingLevelService nursingLevelService;


    /**
     * 查询所有护理等级
     * @return
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult getAll(){
        logger.info("查询所有护理等级");
        NursingLevel[] result = nursingLevelService.getAll();
        return success(result);

    }


    /**
     * 新增护理等级
     * @param nursingLevelDto
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult add(
            @ApiParam(value = "护理等级数据传输对象")
            @RequestBody NursingLevelDto nursingLevelDto
            ) {
        logger.info("新增护理等级 请求参数：{}",nursingLevelDto);
        nursingLevelService.add(nursingLevelDto);
        return success();
    }


    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(
            @ApiParam(value = "护理等级名称")
            String name,
            @ApiParam(value = "状态（0：禁用，1：启用）")
            Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1")
            Integer pageNum,
            @ApiParam(value = "每页显示条数")
            @RequestParam(value = "pageSize", defaultValue = "10")
            Integer pageSize
    ) {
        logger.info("查询护理等级列表 姓名：{} 状态：{} 当前页码：{} 每页显示条数：{}", name, status, pageNum, pageSize);
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.listByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }
    /**
     * 根据id查询护理等级
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getById(
            @ApiParam(value = "护理等级ID")
            @PathVariable Long id
    ) {
        logger.info("根据id查询护理等级 id:{}",id);
        NursingLevelVo NursingLevelVo = nursingLevelService.getById(id);
        return success(NursingLevelVo);
    }

    /**
     * 编辑护理等级
     * @param nursingLevelDto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("编辑护理等级")
    public ResponseResult update(
            @ApiParam(value = "护理等级数据传输对象")
            @RequestBody NursingLevelDto nursingLevelDto
    ) {
        logger.info("编辑护理等级 请求参数：{}",nursingLevelDto);
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    /**
     * 删除护理等级
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult delete(
            @ApiParam(value = "护理等级id")
            @PathVariable Long id
    ) {
        logger.info("删除护理等级 id:{}",id);
        nursingLevelService.delete(id);
        return success();
    }

    /**
     * 启用/禁用护理等级
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理等级")
    public ResponseResult startOrStopStatus(
            @ApiParam(value = "护理等级id")
            @PathVariable Long id,
            @ApiParam(value = "状态（0：禁用，1：启用）")
            @PathVariable Integer status
    ) {
        logger.info("启用/禁用护理等级 id:{} status:{}",id,status);
        nursingLevelService.startOrStopStatus(id,status);
        return success();
    }
}
